package com.hengxinguotong.zhihuichengjian.fragment;

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.util.DisplayMetrics;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.google.gson.Gson;
import com.hengxinguotong.zhihuichengjian.R;
import com.hengxinguotong.zhihuichengjian.adapter.ViewPagerAdapter;
import com.hengxinguotong.zhihuichengjian.ui.app.BaseFragment;
import com.hengxinguotong.zhihuichengjian.bean.CountBean;
import com.hengxinguotong.zhihuichengjian.bean.OnlineConstruction;
import com.hengxinguotong.zhihuichengjian.ui.ActivityJumper;
import com.hengxinguotong.zhihuichengjian.ui.AreaListActivity;
import com.hengxinguotong.zhihuichengjian.ui.MainActivity;
import com.hengxinguotong.zhihuichengjian.utils.SPUtil;
import com.hengxinguotong.zhihuichengjian.utils.Utils;
import com.hengxinguotong.zhihuichengjian.widget.font.HXTextView;
import com.hengxinguotong.zhihuichengjian.widget.view.NoScrollViewPager;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import lecho.lib.hellocharts.gesture.ZoomType;
import lecho.lib.hellocharts.model.Axis;
import lecho.lib.hellocharts.model.AxisValue;
import lecho.lib.hellocharts.model.ColumnChartData;
import lecho.lib.hellocharts.model.Line;
import lecho.lib.hellocharts.model.LineChartData;
import lecho.lib.hellocharts.model.PointValue;
import lecho.lib.hellocharts.model.SubcolumnValue;
import lecho.lib.hellocharts.model.ValueShape;
import lecho.lib.hellocharts.model.Viewport;
import lecho.lib.hellocharts.util.ChartUtils;
import lecho.lib.hellocharts.view.ColumnChartView;
import lecho.lib.hellocharts.view.LineChartView;
import lecho.lib.hellocharts.model.Column;

/**
 * 政府监管
 * Created by Administrator on 2017/7/20.
 */

public class GovernmentHomeFragment extends BaseFragment implements View.OnClickListener, ViewPager.OnPageChangeListener{

    private View rootView = null;
    private MainActivity mainActivity;

    @BindView(R.id.home_vp)
    ViewPager homeVp;
    @BindView(R.id.point_container)
    LinearLayout pointContainer;
    @BindView(R.id.home_list)
    ImageView homeList;
    @BindView(R.id.home_search)
    HXTextView homeSearch;
    @BindView(R.id.home_address)
    HXTextView homeAddress;
    @BindView(R.id.building_construction)
    HXTextView buildingConstruction;
    @BindView(R.id.access_platform)
    HXTextView accessPlatform;
    @BindView(R.id.supervise_department)
    HXTextView superviseDepartment;
    @BindView(R.id.project_department)
    HXTextView projectDepartment;
    @BindView(R.id.slider)
    View slider;
    @BindView(R.id.department_vp)
    NoScrollViewPager departmentVp;
    @BindView(R.id.project_quality)
    LineChartView projectQuality;
    @BindView(R.id.project_secury)
    LineChartView projectSecury;
    @BindView(R.id.person_number)
    ColumnChartView personNumber;
    @BindView(R.id.equipment_number)
    ColumnChartView equipmentNumber;

    //轮播图的集合
    private List<ImageView> list;
    private Handler handler = new Handler();
    //轮播图当前页
    private int currentPage = 0;
    //监管部门与项目部Fragment集合
    private List<Fragment> fragments;
    //监管部门当前页
    private int currentFragment = 0;
    //底部导航栏蓝色线条长度
    private int screenWidth ;
    private List<PointValue> pointValues ;//图点坐标
    private List<AxisValue> axisXValues ;//图x轴
    private List<Column> columns ;//柱状图柱集合
    private Gson gson;

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        if (rootView == null) {
            rootView = inflater.inflate(R.layout.fragment_goverment_homepage, null);
            ButterKnife.bind(this, rootView);
            mainActivity = (MainActivity) getActivity();
            gson = new Gson();
            initView();
        }else {
            ViewGroup parent = (ViewGroup) rootView.getParent();
            if (parent != null) {
                parent.removeView(rootView);
            }
        }
        ButterKnife.bind(this, rootView);
        return rootView;
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        initPoints();
        initBottomLineWidth();
    }

    @Override
    public void onLazyLoad() {
        getOnlineConstructionCount();//在建工地及接入平台查询
        queryCountByArea("加载中…");//查询特种设备、每天的质量检查或者安全检查数量、从业人员
    }

    //获取在建工地数量及接入平台数量
    private void getOnlineConstructionCount(){
        Utils.requestData(null, mainActivity, "/construction/getOnlineConstructionCount/" + SPUtil.getString(mainActivity, "uuid"), null, new Utils.ListenerJson() {
            @Override
            public void onSuccess(String json) {
                if(!Utils.isEmpty(json)){
                    OnlineConstruction onLine = gson.fromJson(json, OnlineConstruction.class);
                    buildingConstruction.setText(onLine.getValue().getUnderCount() + "");
                    accessPlatform.setText(onLine.getValue().getInsertCount() + "");
                }
            }

            @Override
            public void onFailure(String json) {

            }
        });
    }

    //获取各区从业人员/特种设备/检查次数
    private void  queryCountByArea(String alert){
        Utils.requestData(alert, mainActivity, "/main/queryCount/" + SPUtil.getString(mainActivity, "uuid"), null, new Utils.ListenerJson() {
            @Override
            public void onSuccess(String json) {
                if(!Utils.isEmpty(json)){
                    CountBean countBean = gson.fromJson(json, CountBean.class);
                    process(countBean.getValue());
                }
            }

            @Override
            public void onFailure(String json) {

            }
        });
    }

    private void process(CountBean.CountValue value){
        getAxisPoints(value.getQualityCount().getyData());
        getAxisXLables(value.getQualityCount().getxData());
        initQualityLineChart();//初始化质量自查曲线图

        getAxisPoints(value.getSafetyCount().getyData());
        getAxisXLables(value.getSafetyCount().getxData());
        initSecuryLineChart();//初始化安全自查曲线图

        getAxisXLables(value.getCompanyPersonCount().getxData());
        getColumns(value.getCompanyPersonCount().getyData());
        generatePersonData();//初始化从业人员柱状图

        getAxisXLables(value.getEquipmentCount().getxData());
        getColumns(value.getEquipmentCount().getyData());
        generateEquipmentData();//初始化特种设备柱状图
    }

    private void initView(){
        initHomeVp();
        initDepartmentVp();
    }

    //初始化轮播图
    private void initHomeVp(){
        int[] ivs = new int[]{R.mipmap.banner1, R.mipmap.banner2, R.mipmap.banner3};
        list = new ArrayList<ImageView>();
        for (int i = 0; i < ivs.length; i++) {
            ImageView iv = new ImageView(getActivity());
            iv.setScaleType(ImageView.ScaleType.FIT_XY);
            iv.setImageResource(ivs[i]);
            list.add(iv);
        }
        homeVp.setAdapter(new MyVPAdapter());
        homeVp.setCurrentItem(currentPage);
        homeVp.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                currentPage = position;
                for (int i = 0; i < pointContainer.getChildCount(); i++) {
                    ImageView imageView = (ImageView) pointContainer.getChildAt(i);
                    if (i == position) {
                        imageView.setImageResource(R.mipmap.round);
                    } else {
                        imageView.setImageResource(R.mipmap.round_hui);
                    }
                }
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
        handler.postDelayed(new MyRun(), 2000);
    }

    //初始化轮播图下的小圆点
    private void initPoints(){
        pointContainer.removeAllViews();
        for(int i=0; i<list.size(); i++){
            ImageView dot = new ImageView(mainActivity);
            if(i == currentPage){
                dot.setImageResource(R.mipmap.round);
            }else{
                dot.setImageResource(R.mipmap.round_hui);
            }
            LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout
                    .LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
            if (i > 0) {
                params.leftMargin = 10;//设置圆点边距
            }
            dot.setLayoutParams(params);
            pointContainer.addView(dot);
        }
    }

    //每隔2秒调度轮播图一次
    private class MyRun implements Runnable {

        @Override
        public void run() {
            int item = homeVp.getCurrentItem() + 1;
            homeVp.setCurrentItem(item);
            if (item == list.size()) {
                homeVp.setCurrentItem(0);
            }
            handler.postDelayed(new MyRun(), 2000);
        }
    }

    //初始化项目部和监管部门fragment
    private void initDepartmentVp(){
        fragments = new ArrayList<Fragment>();
        SuperviseFragment superviseFragment = SuperviseFragment.newInstance("supervise");
        fragments.add(superviseFragment);
        SuperviseFragment projectFragment = SuperviseFragment.newInstance("project");
        fragments.add(projectFragment);
        departmentVp.setAdapter(new ViewPagerAdapter(getChildFragmentManager(), fragments));
        departmentVp.setCurrentItem(currentFragment);
        departmentVp.addOnPageChangeListener(this);
    }

    //初始化底部导航线的长度
    private void initBottomLineWidth() {
        DisplayMetrics me = new DisplayMetrics();
        mainActivity.getWindow().getWindowManager().getDefaultDisplay().getMetrics(me);
        //得到屏幕宽度的像素点
        screenWidth = me.widthPixels;
        //得到底部导航线的布局参数类对象
        LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) slider.getLayoutParams();
        //将宽度设置为屏幕宽度的1/2-100
        lp.width = screenWidth / 2 - 100;
        //设置线条边距50
        lp.leftMargin = 50;
        //将布局参数设置回slider
        slider.setLayoutParams(lp);
    }

    //清空项目部和监管部门点击选中状态
    private void clearState(){
        superviseDepartment.setTextColor(getResources().getColor(R.color.TextColorBlack));
        projectDepartment.setTextColor(getResources().getColor(R.color.TextColorBlack));
    }

    //初始化项目部质量自查数统计曲线图
    private void initQualityLineChart(){
        Line line = new Line(pointValues).setColor(Color.parseColor("#ff53bcf5"));  ///折线的颜色
        List<Line> lines = new ArrayList<Line>();
        line.setShape(ValueShape.CIRCLE);//折线图上每个数据点的形状  这里是圆形 （有三种 ：ValueShape.SQUARE  ValueShape.CIRCLE  ValueShape.DIAMOND）
        line.setCubic(true);//曲线是否平滑
        line.setStrokeWidth(1);//线条的粗细，默认是3
        line.setFilled(true);//是否填充曲线的面积
        line.setHasLabels(true);///曲线的数据坐标是否加上备注
		line.setHasLabelsOnlyForSelected(false);//点击数据坐标提示数据（设置了这个line.setHasLabels(true);就无效）
        line.setHasLines(true);//是否用直线显示。如果为false 则没有曲线只有点显示
        line.setHasPoints(true);//是否显示圆点 如果为false 则没有原点只有点显示
        lines.add(line);
        LineChartData data = new LineChartData();
        data.setLines(lines);

        //坐标轴
        Axis axisX = new Axis(); //X轴
        axisX.setHasTiltedLabels(false);  //X轴下面坐标轴字体是斜的显示还是直的，true是斜的显示
//	    axisX.setTextColor(Color.WHITE);  //设置字体颜色
        axisX.setTextColor(Color.parseColor("#D6D6D9"));//灰色

//        axisX.setName("未来几天的天气");  //表格名称
        axisX.setTextSize(11);//设置字体大小
        axisX.setMaxLabelChars(7); ////最多几个X轴坐标，意思就是你的缩放让X轴上数据的个数7<=x<=mAxisValues.length
        axisX.setValues(axisXValues);  //填充X轴的坐标名称
        data.setAxisXBottom(axisX); //x 轴在底部
//	    data.setAxisXTop(axisX); //x 轴在顶部
        axisX.setHasLines(true); //x 轴分割线


        Axis axisY = new Axis();  //Y轴
//        axisY.setName("y轴标注");//y轴标注
        axisY.setTextSize(11);//设置字体大小
        data.setAxisYLeft(axisY);  //Y轴设置在左边
        //data.setAxisYRight(axisY);  //Y轴设置在右边
        // 设置行为属性，支持缩放、滑动以及平移
        projectQuality.setInteractive(true);//是否支持与用户互动
        projectQuality.setZoomEnabled(true);//是否支持缩放
        projectQuality.setZoomType(ZoomType.HORIZONTAL);  //缩放类型，水平
        projectQuality.setMaxZoom((float) 3);//缩放比例
        projectQuality.setLineChartData(data);
        projectQuality.setVisibility(View.VISIBLE);
        /**注：下面的7，10只是代表一个数字去类比而已
         * 尼玛搞的老子好辛苦！！！见（http://forum.xda-developers.com/tools/programming/library-hellocharts-charting-library-t2904456/page2）;
         * 下面几句可以设置X轴数据的显示个数（x轴0-7个数据），当数据点个数小于（29）的时候，缩小到极致hellochart默认的是所有显示。当数据点个数大于（29）的时候，
         * 若不设置axisX.setMaxLabelChars(int count)这句话,则会自动适配X轴所能显示的尽量合适的数据个数。
         * 若设置axisX.setMaxLabelChars(int count)这句话,
         * 33个数据点测试，若 axisX.setMaxLabelChars(10);里面的10大于v.right= 7; 里面的7，则
         刚开始X轴显示7条数据，然后缩放的时候X轴的个数会保证大于7小于10
         若小于v.right= 7;中的7,反正我感觉是这两句都好像失效了的样子 - -!
         * 并且Y轴是根据数据的大小自动设置Y轴上限
         * 若这儿不设置 v.right= 7; 这句话，则图表刚开始就会尽可能的显示所有数据，交互性太差
         */
        Viewport v = new Viewport(projectQuality.getMaximumViewport());
        v.left = 0;
        v.right= 7;
        projectQuality.setCurrentViewport(v);
    }

    /*
     *获取线形图柱状图x轴坐标
     */
    private void getAxisXLables(String[] xData){
        axisXValues = new ArrayList<AxisValue>();
        for(int i = 0; i < xData.length; i++ ){
            AxisValue value = new AxisValue(i);//值是在哪显示 i 是指 第i个柱状图
            value.setLabel(xData[i]);//设置显示的文本，默认为柱状图的位置
            axisXValues.add(value);
        }
    }
    /**
     * 质量图表的每个点的显示
     */
    private void getAxisPoints(String[] yData) {
        pointValues = new ArrayList<PointValue>();
        for (int i = 0; i < yData.length; i++) {
            Float f = Float.parseFloat(yData[i]);
            pointValues.add(new PointValue(i, f));
        }
    }

    /*
     *获取从业人员柱状图每个柱的显示
     */
    private void getColumns(String[] yData){
        columns = new ArrayList<Column>();
        int numColumns = yData.length;//柱状图的数量
        int numSubcolumns = 1;//设置每个柱状图显示的颜色数量(每个柱状图显示多少块)
        for(int i = 0; i < numColumns; i++ ){
            List<SubcolumnValue> values = new ArrayList<SubcolumnValue>();
            Float f = Float.parseFloat(yData[i]);
            for (int j = 0; j < numSubcolumns; ++j) {
                SubcolumnValue value = new SubcolumnValue(f, ChartUtils.pickColor());//第一个值是数值(值>0 方向朝上，值<0，方向朝下)，第二个值是颜色
                values.add(value);
            }
            Column column = new Column(values);//一个柱状图的实例
            column.setHasLabels(true);//设置是否显示每个柱状图的高度，
            column.setHasLabelsOnlyForSelected(false);//点击的时候是否显示柱状图的高度，和setHasLabels()和用的时候，setHasLabels()失效
            columns.add(column);
        }
    }

    //初始化项目部安全自查数统计曲线图
    private void initSecuryLineChart(){
        Line line = new Line(pointValues).setColor(Color.parseColor("#ff53bcf5"));  ///折线的颜色
        List<Line> lines = new ArrayList<Line>();
        line.setShape(ValueShape.CIRCLE);//折线图上每个数据点的形状  这里是圆形 （有三种 ：ValueShape.SQUARE  ValueShape.CIRCLE  ValueShape.SQUARE）
        line.setCubic(true);//曲线是否平滑
        line.setStrokeWidth(1);//线条的粗细，默认是3
        line.setFilled(true);//是否填充曲线的面积
        line.setHasLabels(false);///曲线的数据坐标是否加上备注
		line.setHasLabelsOnlyForSelected(true);//点击数据坐标提示数据（设置了这个line.setHasLabels(true);就无效）
        line.setHasLines(true);//是否用直线显示。如果为false 则没有曲线只有点显示
        line.setHasPoints(false);//是否显示圆点 如果为false 则没有原点只有点显示
        lines.add(line);
        LineChartData data = new LineChartData();
        data.setLines(lines);

        //坐标轴
        Axis axisX = new Axis(); //X轴
        axisX.setHasTiltedLabels(false);  //X轴下面坐标轴字体是斜的显示还是直的，true是斜的显示
//	    axisX.setTextColor(Color.WHITE);  //设置字体颜色
        axisX.setTextColor(Color.parseColor("#D6D6D9"));//灰色

//        axisX.setName("未来几天的天气");  //表格名称
        axisX.setTextSize(11);//设置字体大小
        axisX.setMaxLabelChars(7); ////最多几个X轴坐标，意思就是你的缩放让X轴上数据的个数7<=x<=mAxisValues.length
        axisX.setValues(axisXValues);  //填充X轴的坐标名称
        data.setAxisXBottom(axisX); //x 轴在底部
//	    data.setAxisXTop(axisX); //x 轴在顶部
        axisX.setHasLines(true); //x 轴分割线


        Axis axisY = new Axis();  //Y轴
//        axisY.setName("y轴标注");//y轴标注
        axisY.setTextSize(11);//设置字体大小
        data.setAxisYLeft(axisY);  //Y轴设置在左边
        //data.setAxisYRight(axisY);  //Y轴设置在右边
        // 设置行为属性，支持缩放、滑动以及平移
        projectSecury.setInteractive(true);//与用户互动
        projectSecury.setZoomType(ZoomType.HORIZONTAL);  //缩放类型，水平
        projectSecury.setMaxZoom((float) 3);//缩放比例
        projectSecury.setLineChartData(data);
        projectSecury.setVisibility(View.VISIBLE);
        /**注：下面的7，10只是代表一个数字去类比而已
         * 尼玛搞的老子好辛苦！！！见（http://forum.xda-developers.com/tools/programming/library-hellocharts-charting-library-t2904456/page2）;
         * 下面几句可以设置X轴数据的显示个数（x轴0-7个数据），当数据点个数小于（29）的时候，缩小到极致hellochart默认的是所有显示。当数据点个数大于（29）的时候，
         * 若不设置axisX.setMaxLabelChars(int count)这句话,则会自动适配X轴所能显示的尽量合适的数据个数。
         * 若设置axisX.setMaxLabelChars(int count)这句话,
         * 33个数据点测试，若 axisX.setMaxLabelChars(10);里面的10大于v.right= 7; 里面的7，则
         刚开始X轴显示7条数据，然后缩放的时候X轴的个数会保证大于7小于10
         若小于v.right= 7;中的7,反正我感觉是这两句都好像失效了的样子 - -!
         * 并且Y轴是根据数据的大小自动设置Y轴上限
         * 若这儿不设置 v.right= 7; 这句话，则图表刚开始就会尽可能的显示所有数据，交互性太差
         */
        Viewport v = new Viewport(projectSecury.getMaximumViewport());
        v.left = 0;
        v.right= 7;
        projectSecury.setCurrentViewport(v);
    }

    //初始化人员统计柱形图
    private void generatePersonData() {
        // Column can have many subcolumns, here by default_grey I use 1 subcolumn in each of 8 columns.
        ColumnChartData mColumnChartData = new ColumnChartData();//表格的数据实例
        mColumnChartData.setColumns(columns);
        Axis axisX = new Axis();
//       axisX.setInside(true);//是否显示在里面，默认为false
        axisX.setValues(axisXValues);
        Axis axisY = new Axis().setHasLines(true);
//      axisX.setName("Axis X(涂涂的坐标轴)");//设置X轴的注释
//      axisY.setName("Axis Y");//设置Y轴的注释
        mColumnChartData.setAxisXBottom(axisX);//设置X轴显示的位置
        mColumnChartData.setAxisYLeft(axisY);//设置Y轴显示的位置
        personNumber.setColumnChartData(mColumnChartData);//为View设置数据
        personNumber.setZoomType(ZoomType.HORIZONTAL);//缩放类型 水平
        personNumber.setMaxZoom((float) 3);//缩放比例
    }

    //初始化特种设备统计柱形图
    private void generateEquipmentData() {
        // Column can have many subcolumns, here by default_grey I use 1 subcolumn in each of 8 columns.
        ColumnChartData mColumnChartData = new ColumnChartData();//表格的数据实例
        mColumnChartData.setColumns(columns);
        Axis axisX = new Axis();
//       axisX.setInside(true);//是否显示在里面，默认为false
        axisX.setValues(axisXValues);
        Axis axisY = new Axis().setHasLines(true);
//      axisX.setName("Axis X(涂涂的坐标轴)");//设置X轴的注释
//      axisY.setName("Axis Y");//设置Y轴的注释
        mColumnChartData.setAxisXBottom(axisX);//设置X轴显示的位置
        mColumnChartData.setAxisYLeft(axisY);//设置Y轴显示的位置
        equipmentNumber.setColumnChartData(mColumnChartData);//为View设置数据
        equipmentNumber.setZoomType(ZoomType.HORIZONTAL);//缩放类型 水平
        equipmentNumber.setMaxZoom((float) 3);//缩放比例
    }

    private String url;
        @OnClick({R.id.home_list, R.id.home_search, R.id.supervise_department, R.id.project_department,
                R.id.left_ll, R.id.right_ll, R.id.quality_ll, R.id.secury_ll, R.id.person_ll, R.id.equipment_ll})
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.home_list:
                Intent intent = new Intent(mainActivity, AreaListActivity.class);
                startActivity(intent);
                break;
            case R.id.home_search:

                break;
            case R.id.supervise_department:
                clearState();
                departmentVp.setCurrentItem(0);
                superviseDepartment.setTextColor(getResources().getColor(R.color.main_color));
                break;
            case R.id.project_department:
                clearState();
                departmentVp.setCurrentItem(1);
                projectDepartment.setTextColor(getResources().getColor(R.color.main_color));
                break;
            case R.id.left_ll:
                url = "/construction/toConstruction/" + SPUtil.getString(mainActivity, "uuid");
                ActivityJumper.jumpToWebView(url, "在建工地", mainActivity);
                break;
            case R.id.right_ll:
                url = "/construction/toConstructionInto/" + SPUtil.getString(mainActivity, "uuid");
                ActivityJumper.jumpToWebView(url, "二级菜单", mainActivity);
                break;
            case R.id.quality_ll:
                url = "/inspection/toCheckQuality/" + SPUtil.getString(mainActivity, "uuid");
                ActivityJumper.jumpToWebView(url, "二级菜单", mainActivity);
                break;
            case R.id.secury_ll:
                url = "/inspection/toCheckSafe/" + SPUtil.getString(mainActivity, "uuid");
                ActivityJumper.jumpToWebView(url, "二级菜单", mainActivity);
                break;
            case R.id.person_ll:
                url = "/person/toCount/" + SPUtil.getString(mainActivity, "uuid");
                ActivityJumper.jumpToWebView(url, "二级菜单", mainActivity);
                break;
            case R.id.equipment_ll:

                break;
        }
    }

    @Override
    public void onPageScrolled(int position, float offset, int positionOffsetPixels) {
        //得到bottom_line的LayoutParams参数对象
        LinearLayout.LayoutParams lp =(LinearLayout.LayoutParams) slider.getLayoutParams();
        int marginLeft = 0 ;
        if(currentFragment == position)
        {
            marginLeft = (int)(currentFragment*(screenWidth/2) + offset * (screenWidth/2)) + 50;
            //为布局参数的左边距赋值
            lp.leftMargin = marginLeft ;
            slider.setLayoutParams(lp);
        }else
        {
            marginLeft = (int)(currentFragment*(screenWidth/2) - ((1-offset) * (screenWidth/2))) + 50;
            lp.leftMargin = marginLeft ;
            slider.setLayoutParams(lp);
        }
    }

    @Override
    public void onPageSelected(int position) {
        currentFragment = position;
    }

    @Override
    public void onPageScrollStateChanged(int state) {

    }

    private class MyVPAdapter extends PagerAdapter {

        @Override
        public int getCount() {
            return list.size();
        }

        @Override
        public boolean isViewFromObject(View arg0, Object arg1) {
            return arg0 == arg1;
        }

        @Override
        public Object instantiateItem(ViewGroup container, int position) {
            container.addView(list.get(position));
            return list.get(position);
        }

        @Override
        public void destroyItem(ViewGroup container, int position, Object object) {
            container.removeView((View) object);
        }
    }

}
